<template>
    <!-- <div>封堵白名单</div> -->
    <a-row>
      <a-col>
        <a-card :bordered="false" style="margin-bottom: 10px">
          <!-- 查询区域 -->
          <div class="table-page-search-wrapper">
            <a-form-model ref="ruleForm" :model="pageFilter" :label-col="labelCol" :wrapper-col="wrapperCol">
              <a-row style="display:flex">
                <a-col :span="6">
                <a-form-model-item label="涉诈网站">
                    <a-input placeholder="请输入任务名称" v-model="pageFilter.fraudUrl"/>
                </a-form-model-item>
              </a-col>
                <a-col :span="6">
                <a-form-model-item label="诈骗类型" style="margin-left:0px">
                  <a-select v-model="pageFilter.fraudType" allowClear placeholder="请选择" style="width:100%;">
                    <a-select-option value="">全部</a-select-option>
                    <a-select-option v-for="(item, key) in fraud_typeArr" :key="key" :value="item.value">{{
                      item.title
                    }}
                    </a-select-option>
                  </a-select>
                </a-form-model-item>
                </a-col>
                <a-col :span="6">
                <a-form-model-item label="传输方式" style="margin-left:0px">
                  <a-select v-model="pageFilter.transmissionWay" allowClear placeholder="请选择" style="width:100%;">
                    <a-select-option v-for="(item, key) in transmissionWay" :key="key" :value="item.value">{{
                      item.title
                    }}
                    </a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col>  
              <a-col :span="6" style="margin-left:0px">
                    <a-space :size="6">
                      <a-button type="primary" @click="onQuery" icon="search">查询</a-button>
                      <a-button @click="onResetForm" icon="reload">重置</a-button>
                    </a-space>
                  </a-col>   
              </a-row>
              <a-col :span="6">
                <a-form-model-item label="接收状态">
                    <a-select style="width:100%" v-model="pageFilter.receiveStatus">
                      <a-select-option v-for="(item, key) in receiveStatus" :key="key" :value="item.value">{{
                      item.title
                    }}
                  </a-select-option>
                    </a-select>
                </a-form-model-item>
              </a-col>
              <a-col :span="6">
                <a-form-model-item label="接收时间">
                    <a-range-picker />
                </a-form-model-item>
              </a-col>
            </a-form-model>
          </div>
        </a-card>
        <a-card :bordered="false">
          <div>
            
            <a-button type="primary" @click="onExport" style="margin-right:10px">导出</a-button>
            <z-table ref="table" rowKey="id" :showAlert="false" :showSelection="true" :loading="loading"
              :columns="columns" :dataSource="pageData" @selectedRowKey="onSelectedRow" @change="onTableChange">
              <template slot="fraudType" slot-scope="text, record">
                <span>{{ fraud_typeArr[record.fraudType-1]?fraud_typeArr[record.fraudType-1].text:'' }}</span>
              </template>
            </z-table>
          </div>
          
        </a-card>
      </a-col>
    </a-row>
  </template>
  
  <script>
  import { getDictItemsFromCache } from '@/api/api'
  import { pageBlockingGovernanceLog,exportBlockingGovernanceLog } from '@/api/plugging/Police'
  import { downLoadMix } from '@/utils/export-util/util'
  export default {
    mounted () {
      this.onQuery()
    },
    data () {
      return {
        idsDTO:{
        ids:[]
        },
        receiveStatus:[
        {
          title:'失败',
          value:0
        },
        {
          title:'成功',
          value:1
        },
      ],
      transmissionWay:[
        {
          title:'kafka',
          value:1
        },
        {
          title:'ftp',
          value:2
        },
        {
          title:'内部接口',
          value:3
        },
      ],
        labelCol: { span: 5 },
        wrapperCol: { span: 16 },
        loading: false,
        fraud_typeArr: getDictItemsFromCache('case_fraud_type'),
        pageFilter: {
          pageNo: 1,
          pageSize: 10,
        },
        pageData: {
        
        },
        columns:[
          {
            title: '序号',
            dataIndex: 'order',
            width: 60,
            align: 'center',
            customRender: (text, record, index) =>
              `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
          },
          {
            title: '数据编号',
            dataIndex: 'dataNo',
            align: 'center',
          },
          {
            title: '数据来源',
            dataIndex: 'dataSource',
            align: 'center',
            customRender:text => `${text == 1?'kafka数据信息':text == 2?'SFTP文件':'涉诈网址上报'}`
          },
          {
            title: '传输方式',
            dataIndex: 'transmissionWay',
            align: 'center',
            customRender:text => `${text == 1?'kafka':text == 2?'ftp':'内部接口'}`
          },
          {
            title: '接收时间',
            dataIndex: 'receivedTime',
            align: 'center',
          },
          {
            title: '接收状态',
            dataIndex: 'receiveStatus',
            align: 'center',
            customRender:text => `${text == 1?'成功':'失败'}`
          },
          {
            title: '失败原因',
            dataIndex: 'failReason',
            align: 'center',
          },
          {
            title: '诈骗网站',
            dataIndex: 'fraudUrl',
            align: 'center',
          },
          {
            title: '诈骗类型',
            dataIndex: 'fraudType',
            align: 'center',
            scopedSlots: { customRender: 'fraudType' },
          },
          {
            title: '发现时间',
            dataIndex: 'discoveryTime',
            align: 'center',
          },

        ]
      }
    },
    methods: {
      onExport(){
        exportBlockingGovernanceLog(this.idsDTO).then(
        async res => {
            if(res && res.size>0) {
              const fileName = '数据治理日志.xls'
              await downLoadMix(res, fileName)
            } else {
              this.$message.warn("导出失败！")
            }
      })
        .catch((e) => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
    },
      NewSubmission(){
        this.$router.push({
        path: '/plugging/police/InvolvingFraud/NewSubmission',
        query: {}
      })
      },
      // aa(){
      //   this.$router.push({
      //   path: '/plugging/police/InvolvingFraud/EditSubmission',
      //   query: {}
      // })
      // },
      // bb(){
      //   this.$router.push({
      //   path: '/plugging/police/InvolvingFraud/ReportDetails',
      //   query: {}
      // })
      // },
      onQuery() {
        this.pageFilter.pageNo = 1
        this.refreshTable()
        console.log(this.pageData);
      },
      //重置
      onResetForm() {
        this.pageFilter = {
          pageNo: 1,
          pageSize: 10,
          departmentId: this.departmentId
        }
        this.refreshTable()
      },
      onSelectedRow(keys) {
        this.selectKeys = keys
        this.idsDTO.ids = keys
        console.log(this.idsDTO.ids);
        this.isDisabled = keys.length > 0 ? false : true
      },
      onTableChange(pagination, pageFilter, sorter) {
        let keyMap = { currentPage: 'pageNo' }
        let paginations = Object.keys(pagination).reduce((newData, key) => {
          let newKey = keyMap[key] || key
          newData[newKey] = pagination[key]
          return newData
        }, {})
        this.pageFilter = Object.assign({}, this.pageFilter, paginations)
        this.refreshTable()
      },
      refreshTable() {
        this.loading = true
        pageBlockingGovernanceLog(this.pageFilter).then( res => {
          if (res.success) {
            this.pageData = res.result ? res.result : {}
            this.loading = false
          } else {
            this.$message.success(res.message)
            this.loading = false
          }
        })
          .catch((e) => {
            this.loading = false
            this.$message.warn('请求失败！')
          })
      },
    }
  }
  </script>
  
  <style lang="less" scoped>
  .search-wrapper-btn {
    position: absolute;
    right: 8%;
    top: 22px;
    z-index: 100;
  }
  </style>